home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- Date: Wed, 06 Mar 96 01:23:49 GMT
- Organization: none
- Message-ID: <826075429snz@genesis.demon.co.uk>
- References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com> <4gvksnINNnug@anvil.ugrad.cs.ubc.ca> <TANMOY.96Feb29100937@qcd.lanl.gov> <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
-
- >In article <TANMOY.96Feb29100937@qcd.lanl.gov>,
- >Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> wrote:
-
- >>except when it is the direct operand of the & operator or the direct
- >>operand of the sizeof operator. (You say that later: but that is much
- >>later :-).
- >
- >Well, the operand of a sizeof operator can be an expression, or a parenthesized
- >type name. If it is an expression, it is not evaluated, but only checked for
- >those attributes which determine the size of the lvalue. Conceptually, the
- >expression still has a value, albeit one which is thrown away.
-
- If the expression has a value to be thrown away it must have been evaluated
- However, as you say, it isn't. This is important where side-effects are
- concerned. What are performed are the type derivations which form part of
- normal expression evaluation.
-
- >In the case of &, the operator does require the ``cast-expression''
- >syntactic unit, but again, it is interested in something other than the
- >straightforward value of the expression. The subject must be marked as an
- >lvalue that meets certain criteria. For all I know, in the expression
- >
- > &myarray
- >
- >where myarray is an array of char, the myrray constituent could still be
- >treated as an expression that produces a pointer, a value that is ignored
- >because some other attribute of the expression is interesting to the &
- >operator.
-
- It isn't necessary to generate values and then discard them, even
- conceptually (and the language definition doesn't). myarray here is
- a primary expression which 'evaluates' to an lvalue. An lvalue has a type
- and a reference to the underlying object. sizeof just derives a number from
- the type. & generates a pointer to the object using both type and reference
- (where an address is available, it isn't for example in an lvalue with
- register type). In something like:
-
- ptr = myarray;
-
- the 'value' (or rvalue if you like) of the array lvalue is taken. The
- rules for taking the rvalue of an array lvalue are to generate a pointer
- to the array object's first element. ptr here is on the lhs of = which
- also requires an lvalue. = uses the type and reference of the lvalue to
- write a value to the object. ++ptr is interesting because it effectively
- treats ptr as both an lvalue and an rvalue (if you think of it as
- ptr = ptr+1)
-
- >By the same reasoning, if I have an integer 'i' initialized to 3, and write
- >
- > &i
- >
- >the i constituent is still an expression whose value is 3. However, the &
- >construct is interested in that i is an lvalue of a certain type and address,
- >and that it has an address, and the (conceptually present) computational value
- >is ignored.
-
- The point is that i by itself is simply an lvalue which has int type and
- designates an int object (ISO 6.3.1). Only when you actually
- put it in a context that requires an rvalue is the value that the object holds
- read. i by itself is not an expression with the value 3.
-
- >It's always useful to think of expressions and other constructs as not
- >computing only values, but also all kinds of other attributes, including type,
- >l- versus r- value markers and so forth, any of which can be the item of
- >interest to a dominating syntactic unit in favor of the value.
-
- True, and it is the 'dominating syntactic unit' (which I will simply refer
- to as 'context') which determines whether an lvalue will be converted to an
- rvalue.
-
- >In saying what the expression 'myarray' is, I should have been more thorough by
- >mentioning what other attributes it has, not just the principal computational
- >pointer value. Thus, here is my second attempt:
- >
- >myarray is an expression whose evaluation calls for the generation of a value,
- >whose type is pointer to char and which points to the first element of myarray.
- >However, the expression myrray also has other attributes. It is an lvalue which
- >can be the subject of sizeof() and & operators, which are not interested in
- >computing the pointer value, but which look at the type and storage attributes
- >of myarray itself. It is not a modifiable lvalue, hence it cannot be assigned
- >to.
-
- No, myarray is a non-modifiable lvalue whose type is array of char and which
- designates the object that is the entire array. Quantities such as a pointer
- to the array's first element can be derived from that where the context calls
- for them.
-
- ...
-
- >The bottom line is that it's not necessary to view the subjects of & and sizeof
- >as special cases; expressions are the same in the context of these operators as
- >they are anywhere else, and can be seen as producing the same values.
-
- sizeof is special because it affects the entire evaluation process of its
- operand (i.e. inhibits everything bar type derivation). & like
- other operators simply performs actions using its operand's result.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-